#include<iostream>
#include<gsl/gsl_randist.h>
#include<stdlib.h>
using namespace std;
int numDisks;
int maxQueueLen;
int requests;
unsigned int * n;
double * p;
double result =1.0;

int 
sumBefore(int diskId){
	int sum = 0;
	for(int i=0;i<diskId;i++){
		sum += n[i];
	}
	return sum;
}

void 
dfs(int diskId){
	if(diskId == numDisks -1){
		n[diskId] = requests - sumBefore(diskId);
		if(n[diskId] < 0)
			n[diskId] =0;
		if(n[diskId] <= maxQueueLen){
			double now = gsl_ran_multinomial_pdf(numDisks,p,n);
			result -= now;
			if(result < 0.0)
				result = 0.0;
		}
		return ;
	}
	for(int i=0;i<=maxQueueLen;i++){
		if(sumBefore(diskId) + i <= requests)
			n[diskId] = i;
		else
			n[diskId] =0;
		dfs(diskId + 1);
	}
	return ;
}


int 
main(int argc,char *argv[]){
	if(argc!=4){
		printf("usage : ./a.out numdisks maxQueuelen requests \n");
		exit(1);
	}
	numDisks = atoi(argv[1]);
	maxQueueLen = atoi(argv[2]);
	requests = atoi(argv[3]);	
	cout<<"\t"<<numDisks<<"\t\t"<<maxQueueLen<<"\t\t"<<requests;
	p =(double*) malloc(sizeof(double)*numDisks);
	n = (unsigned int *)malloc(sizeof(int) *numDisks);
	for(int i=0;i<numDisks;i++){
		p[i] = 1/(double)numDisks;
	}
	dfs(0);
	printf("\t\t  %.8f\n",result);
	return 0;
}
